﻿<?php
/**
 * 轻云网络验证系统
 * =======================================================
 * 版权所有(C) 2019-2039 daenx.cn，并保留所有权利。
 * 作者：Daen大恩
 * 作者QQ: 1330166565
 * 开发群：661059773
 * =======================================================
 */

include 'data/weby.php';
$username=$_GET["username"];
$domain=$_GET["domain"];
$qq=$_GET["qq"];
$km=$_GET["km"];
$nowtime=time();
$pass=$_GET["pass"];

if($_GET['do']=="do"){
	if($domain==""){
		header('Content-type:text/html;charset=utf-8');
		echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">机器人QQ不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
	}else{
		header('Content-type:text/html;charset=utf-8');
		if($km==""){
			header('Content-type:text/html;charset=utf-8');
			echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密不能为空!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
		}else{
			if($km=="admin"){
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密有误或无法使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
			}else{
			$sql="SELECT * FROM `cami` where km='$km' limit 1";//判断卡密
			$row=mysqli_fetch_array(mysqli_query($con,$sql));
			if($row){
				
				//添加授权
				$yme=$row['ytime'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				$up=$row['up'];
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				
					mysqli_query($con,"DELETE FROM `cami` where `id` = $kmid ");//删除卡密
					$status = '已使用';
					$status = base64_encode($status);
					$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$yme','$cp');";
					mysqli_query($con,$sql);
					
					
				if($rows > 0){
					$zhurenqq = $row['qq'];
					if($row['time']=="free")
					{
						if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme);}
					}
					else
					{
						if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme,$row['time']);}
						
					}
					$sql = "UPDATE `authorize` SET `time` = '$time' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
					}else{
					$zhurenqq = $qq;
					if($yme == '+100year')
						{$time = '';}
					else
						{$time = strtotime($yme);}
					$sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,  `qq`,  `time`, `syskey`, `ycp`, `dl`, `up`) VALUES ('$domain','$domain','$km','$zhurenqq',  '$time', '$km', '$cp', '普通用户', '$up');";//添加授权
					mysqli_query($con,$sql); 
					
				}
				if($time == null){$dsc="永久";}
				else{$dsc=date("Y-m-d",$time);}
				header('Content-type:text/html;charset=utf-8');
				echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">授权成功<br>机器人QQ：".$domain."<br>主人QQ：".$zhurenqq."<br>产品：".$cp."<br>到期日期：".$dsc."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
					
					
				}else{
					
				$sql="SELECT * FROM `cami_ye` where km='$km' limit 1";//判断卡密
				$row=mysqli_fetch_array(mysqli_query($con,$sql));
				if($row){
				//添加授权
				$ye=$row['ye'];
				$cp=$row['cp'];		
				$kmid=$row[id];
				$up=$row['up'];
				
				mysqli_select_db($dbname);
				mysqli_query($con,"set names utf8");
				$sql="select * from authorize where domain='$domain' and ycp='$cp'";
				$query=mysqli_query($con,$sql);
				$rows = mysqli_num_rows($query);
				$row=mysqli_fetch_assoc($query);
				
				mysqli_query($con,"DELETE FROM `cami_ye` where `id` = $kmid ");//删除卡密
					$status = '已使用';
					$status = base64_encode($status);
					$sql = "INSERT INTO `camilog` (`domain`, `km`, `time`,  `status`,  `ytime`,`cp`) VALUES ('$domain', '$km', '$nowtime', '$status', '$ye','$cp');";
					mysqli_query($con,$sql);
					
					$ip = getip();
					
					
				if($rows > 0){
					$zhurenqq = $row['qq'];
					$zye = $row['rmb'] + $ye;
					$sql = "INSERT INTO `log_rmb` (`domain`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$domain', '$nowtime', '$cp', '+$ye', '$zye', '网页使用-余额卡密','$ip');";//添加流水日志
					mysqli_query($con,$sql);
					$sql = "UPDATE `authorize` SET `rmb` = '$zye' WHERE domain='$domain' and ycp='$cp';";
					mysqli_query($con,$sql); 
			}else{
					$zye = $ye;
					$sql = "INSERT INTO `log_rmb` (`domain`,`time`,`cp`,`rmb`,`zrmb`,`bz`,`ip`) VALUES ('$domain', '$nowtime', '$cp', '+$ye', '$zye', '网页使用-余额卡密','$ip');";//添加流水日志
					mysqli_query($con,$sql);
					$sql = "INSERT INTO `authorize` (`username`,`domain`,`pass`,  `qq`,  `time`, `syskey`, `ycp`, `dl`, `rmb`, `up`) VALUES ('$domain','$domain','$km','$zhurenqq',  'free', '$km', '$cp', '普通用户','$zye','$up');";//添加授权
					mysqli_query($con,$sql); 
				}
				
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '280px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">充值成功<br>机器人QQ：".$domain."<br>主人QQ：".$zhurenqq."<br>产品：".$cp."<br>现有余额：".$zye."</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
					mysqli_close();
					
				}else{
					header('Content-type:text/html;charset=utf-8');
					echo("<script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/js/jquery.min.js\"></script><script language=\"javascript\" type=\"text/javascript\" src=\"/data/assets/layer/layer.js\"></script><script>layer.open({  type: 1  ,title: false   ,closeBtn: false  ,area: '200px;'  ,shade: 0.8  ,id: 'LAY_layuipro'   ,resize: false  ,btn: ['确定']  ,moveType: 1   ,content: '<div style=\"padding: 30px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;\">卡密错误或者已被使用!</div>'  ,success: function(layero){ var btn = layero.find('.layui-layer-btn');  btn.find('.layui-layer-btn0').attr({ href: 'buy.php' });  }});</script>");
				}
			}
		}
	}
}}


?>
<?php
include 'head.php';
?>
<title>自助授权 - <?php echo $title;?></title>
<link href="static/css/music.css" rel="stylesheet">
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/animate.min.css" rel="stylesheet">
<link href="static/css/font-awesome.min.css" rel="stylesheet">
<link href="static/css/form.css" rel="stylesheet">
<link href="static/css/calendar.css" rel="stylesheet">
<link href="static/css/file-manager.css" rel="stylesheet">
<link href="static/css/style.css" rel="stylesheet">
<link href="static/css/icons.css" rel="stylesheet">
<link href="static/css/generics.css" rel="stylesheet">
<link rel="shortcut icon" href="<?php echo $route?>img/LightCloud.png" type="image/x-icon" />
<STYLE>.loginscreen.middle-box{width:300px;}.middle-box{max-width:400px;z-index:100;margin:0 auto;padding-top:100px;}</STYLE>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?0de8a795db3f2bcc6c9c374ab7468d22";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body id="skin-blur-violate">
<section id="main">
<section class="middle-box " align="center">
<div class="tile p-15">
<div class="container">
<img id="btnAudio" class="profile-pic animated" src="http://q.qlogo.cn/headimg_dl?bs=qq&dst_uin=<?php echo $kfqq; ?>&fid=blog&spec=100" alt="">
<form action="buy.php" class="form-sign" method="get">
<input type="hidden" name="do" value="do">
<div class="form-group">
<label for="exampleInputEmail1">自助授权</label>
<div class="panel-body">
 <label for="exampleInputEmail1">—— 此处可续费、可激活 ——</label>
 <br>
 <input type="text" name="km" class="form-control" placeholder="请输入卡密，会自动识别产品" required>
 <br>
 <!--<label for="exampleInputEmail1">机器人QQ</label>-->
 <input type="text" name='domain' class="form-control" placeholder="请输入机器人QQ" required>
 <br>
 <!--<label for="exampleInputEmail1">主人QQ</label>-->
 <input type="text" name='qq' class="form-control" placeholder="请输入主人QQ" required>
</div>
<div class="form-group">
</label>
</div>
<div class="fileupload fileupload-new" data-provides="fileupload">
<button type="submit" class="btn btn-block btn-alt" value="确定" href="#">确认授权</button>
</div>
<a data-toggle="modal" href="javascript:history.back(-1)" class="btn btn-sm m-t-10">返回上一页</a>
<a data-toggle="modal" href="/get" class="btn btn-sm m-t-10">更换授权</a>
<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=<?php echo $kfqq; ?>&amp;site=qq&amp;menu=yes" target="_blank" class="btn btn-sm m-t-10">联系客服</a>
<a href="/daili.php" target="_blank" class="btn btn-sm m-t-10">购买授权</a>
</form>
</div>
<script src="get/qrlogin.js"></script>
<script src="static/js/jquery.min.js"></script>  
<script src="static/js/jquery-ui.min.js"></script>  
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/scroll.min.js"></script>  
<script src="static/js/calendar.min.js"></script>  
<script src="static/js/feeds.min.js"></script>  
<script src="static/js/elfinder.min.js"></script>  
<script src="static/js/music.js"></script>
<script type="text/javascript">
            $(document).ready(function() {
                 $('#fileManager').elfinder({
                      resizable: false,
                      url : 'php/connector.minimal.php',  // connector URL (REQUIRED)
                      uiOptions : {
                      toolbar : [
                              ['back', 'forward', 'home', 'reload'],
                              ['mkdir', 'mkfile', 'upload'],
                              ['view', 'sort'],
                              ['search']
                      ]},
                      height: 500
                 });
                 
                 $('.elfinder-cwd-wrapper, .elfinder-navbar').niceScroll();
            });
</script>
</body>
</html>